﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YRevitJig;

namespace HYFloorPipeModule
{
	public class PipeCreateJig : XUiJigBase
	{
		public PipeCreateJig(UIDocument uiDoc) : base(uiDoc)
		{
			this.ResetPoint = XUiJigBase.EResetPoint.eNoOper;
		}

		public XYZ PickStartPoint(string strPrompt)
		{
			try
			{
				this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
			}
			catch
			{
				this.StartPoint = null;
			}
			return this.StartPoint;
		}

		public XYZ PickEndPoint(string strPrompt)
		{
			try
			{
				this.ResetPoint = XUiJigBase.EResetPoint.eByAxis;
				this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
				while (this.EndPoint.IsAlmostEqualTo(this.StartPoint))
				{
					MessageBox.Show("选择的两点过于接近，无法创建！", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
				}
				this.StartPoint = this.EndPoint;
			}
			catch
			{
				this.EndPoint = null;
			}
			return this.EndPoint;
		}

		public override void Draw(PaintEventArgs paintEventArgs)
		{
			base.Draw(paintEventArgs);
			if (this.StartPoint != null)
			{
                System.Drawing.Point ptCur = this.m_ptCur;
				XGraphics g = new XGraphics(paintEventArgs.Graphics, base.JigPen);
				new XLine2D(base.Revit2Client(this.StartPoint), this.m_ptCur).Draw(g);
				return;
			}
		}

		public XYZ StartPoint { get; set; }

		public XYZ EndPoint { get; set; }

		public XUiJigBase.EResetPoint ResetPoint { get; set; }
	}
}
